package 力扣_算法题综合.自己不会但觉得高频;

/**
 * @author zx
 * @create 2023-01-07 0:01
 */
public class 找出字符串中第一个匹配项的下标_28 {
    /**
     * @return 代码很简单,但是不熟练的话做不出来
     */
    public int strStr(String haystack, String needle) {
        for(int i = 0;i <= haystack.length() - needle.length();i++){
            int a = i,b = 0;
            while(b < needle.length() && haystack.charAt(a) == needle.charAt(b)){
                a++;
                b++;
            }
            if(b == needle.length()){
                return i;
            }
        }
        return -1;
    }
}
